#include <string.h>
#include <iostream>
using std::cout;
using std::endl;

void test0(){
    //如果用数组的形式使用字符串
    //记得终止符的设置
    char arr[6] = {'h','e','l','l','o','\0'}; 
    char arr2[] = {'w','o','r','l','d'};
    char arr3[] = "wangdao";

    printf("%p\n",arr);
    printf("%p\n",arr2);

    cout << arr << endl;
    cout << arr2 << endl;
    cout << arr3 << endl;
}

void test1(){
    const char * pstr = "hello";
    /* char * pstr = "hello"; */
    /* pstr[0] = 'X'; */
    cout << pstr << endl;
}

void test2(){
    const char * ps = "world";
    //如果pstr是一个const char *
    //那么其指向的空间上的内容一经初始化就
    //不能再通过这个指针进行修改
    char * pstr = new char[strlen(ps) + 1]();
    strcpy(pstr,ps);

    const char * pstr2 = new char[10]{'h','e','l','l','o'};
    cout << pstr << endl;
    cout << pstr2 << endl;

    delete [] pstr;
    pstr = nullptr;

    delete [] pstr2;
    pstr2 = nullptr;

    /* delete [] ps;//error */
}

int main(void){
    test2();
    return 0;
}
